package prolog.builtins
import prolog.terms._
import prolog.fluents._

final case class new_engine() extends FunBuiltin("new_engine", 4) {
  override def exec(p: Prog) = {
    val files = getArg(0)
    val answer = getArg(1)
    val gs = Conj.toList(getArg(2))
    val db = if (Const.nil == files) p.db
    else {
      val file: Term = files.asInstanceOf[Cons].getHead
      val fname: String = file.asInstanceOf[Const].sym
      new DataBase(fname)
    }
    val q = new Prog(db)
    q.set_query(answer, gs)
    putArg(3, q, p)
  }
}